<?php


namespace app\common\tool;


class StrTool
{
    public static function round_captcha(int $length, $charset = 1)
    {
        $code = '';
        $charsetList = [
            '0123456789',                                                                   # 0
            'abcdefghijklmnopqrstuvwxyz',                                                   # 1
            'ABCDEFGHIJKLMNOPQRSTUVWXYZ',                                                   # 2
            'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',                         # 3
            '23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'                       # 4
        ];

        $characters = $charsetList[$charset];
        for ($i = 0; $i < $length; $i++) {
            $index = mt_rand(0, strlen($characters) - 1);
            $code .= $characters[$index];
        }
        return $code;
    }
}